<template>
  <div>
    <!-- <TopFilter ref="topFilter" :list="topFilterList" :cols="3" :labelWidth="100" :collapse="false" @onCollapse="collapseHandle" @filterChange="handleFilterChange" /> -->
    <FilterTable
      ref="mainTable"
      :fetchapi="fetchapi"
      :params="fetchParams"
      :columns="tableColumns"
      :dataSource = "list"
      columnsRef="aduitOrder"
      :datakey="'records'"
      :onRowSelectChange="handleRowSelectChange"
      :onColumnsChange="columns => (this.tableColumns = columns)"
      :isSelectColumn="false"

    >
      <!-- <template slot="controls" slot-scope="props">
        <el-switch
          @change="aotoAuditOrderSwitchChange"
          v-model="aotoAuditOrderSwitch"
          active-text="自动审单"
          inactive-text="手动审单">
        </el-switch>
      </template> -->
    </FilterTable>
    <div>
    </div>
  </div>
</template>


<script>

import { dictionary } from '@/utils/dictMixin';
import { getList,autoAuditOrderSwitchFuc} from '@/api/partsmanage/trafficParams/orderSetting/index';

export default {
  name: 'aduitOrder',
  mixins: [dictionary],
  components: {

  },
  data() {
    return {
      list:[],
      aotoAuditOrderSwitch:false,
      top: {},
      rowData: {},
      selectList: [],
      tableColumns: this.createTableColumns(),
      isShowpartBuyItems: false,
      fetchapi: getList,
      fetchParams: { xhrAbort: true },
      issearch: false
    };
  },
  mounted() {
    getList().then(res =>{
      if(res.resultCode == 200 ){
        this.list = res.data.records
      }
    });
    this.confirmSearchCustomer();
    findAutoAuditOrder().then(res =>{
      if(res.resultCode == 200 ){
        if(res.data.status == 10011001){
          this.aotoAuditOrderSwitch = true;

        }else if(res.data.status == 10011002){
          this.aotoAuditOrderSwitch = false;

        }else{
          this.aotoAuditOrderSwitch = null;

        }
      }else{
        this.aotoAuditOrderSwitch = null;
      }

    }).catch(err =>{

    })
  },
  methods: {
    aotoAuditOrderSwitchChange(val,id){
      console.log("val===>"+val,id);
      this.$confirm('确认改变审单方式?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
      }).then(() =>{
        autoAuditOrderSwitchFuc({id:id,status:val == 10011001 ? 10011002: 10011001}).then(res =>{
          console.log(res);
          if(res.resultCode == 200 ){
            getList().then(res =>{
              if(res.resultCode == 200 ){
                  this.list = res.data.records
                      }
                    });
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
          }else{
            this.$message({
              type: 'warning',
              message: res.errMsg || '操作失败!'
            });
            this.aotoAuditOrderSwitch = !val;
          }

        }).catch(err =>{
          this.$message({
            type: 'warning',
            message: err.errMsg || '操作失败!'
          });
          this.aotoAuditOrderSwitch = !val;
        })

      }).catch(err =>{
        this.$message({
          type: 'warning',
          message: '已取消!'
        });
        this.aotoAuditOrderSwitch = !val;
      })
    },

    seacherFun(){
      this.issearch = true
    },
    dealercloseHandler(val){
      if(val){
        this.topFilterList.find(x=>x.fieldName=='ownerCode').initialValue=val.dealerCode;
        this.topFilterList.find(x=>x.fieldName=='ownerName').initialValue=val.dealerShortname;
      }
      this.issearch=false;
    },


    createTableColumns() {
      return [
        {
          title: '序号',
          // sorter: true,
          width: 70,
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '订单类型',
          dataIndex: 'paramName',
          filter: true,
          sorter: true,
          filterType: 'input',
          // width: 400,
          align:"center"
        },
        {
          title: '审单方式',
          dataIndex: 'status',
          filter: true,
          sorter: true,
          filterType: 'input',
          align:"center",
          // width: 400,
          render: props => {
                return  <el-switch
          onChange={()=>{this.aotoAuditOrderSwitchChange(props.row.status,props.row.id)}}
          value={props.row.status == 10011001?true:false}
          active-text="自动审单"
          inactive-text="手动审单">
        </el-switch>;
              }
        }

      ];
    },
    collapseHandle() {},
    handleFilterChange(e) {
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign(this.fetchParams, {
        ...e,
        xhrAbort: false,
      });
    },


    // async translateDealer() {
    //   let res = await byAllTranslate();
    //   if (res.resultCode == 200) {
    //     // console.log(res.data, 'res.data::');
    //     let dataList = res.data ? res.data : [];
    //     // console.log(dataList, 'dataList::');
    //     let tempList = dataList.map(x => ({
    //       value: x.dealerCode,
    //       text: x.dealerName
    //     }));
    //     // console.log(tempList, 'tempList::');
    //     this.tableColumns.find(x => x.dataIndex == 'ownerCode').dictItems = tempList;
    //   }
    // },
    handleRowSelectChange(rows) {
      this.selectList = rows;
    },
    showItems(e) {
      this.isShowpartBuyItems = true;
      this.top = e;
    },

  }
};
</script>
